// Copyright (C) 2010 Razvan Constantin.
//
// This file is part of FileBow.
//
// FileBow is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// FileBow is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with FileBow.  If not, see <http://www.gnu.org/licenses/>.

// Stand-alone application for displaying the file navigation dialog.

#include "ui/navigate-dlg.h"

#include <cstring>
#include <iostream>
#include <stdio.h>
#include <string>

#include <gtk/gtk.h>

#include "common/common.h"
#include "logic/navigator.h"
#include "logic/path-tree.h"

using namespace filebow;
using namespace std;

static gboolean verbose = FALSE;
static gchar* project = NULL;

static GOptionEntry entries[] =
{
  { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Enables logging to stderr.", NULL },
  { "project", 'p', 0, G_OPTION_ARG_STRING, &project, "Path to project directory.", NULL },
  { NULL }
};

int main(int argc, char** argv) {
  // Init gtk.
  gtk_init(&argc, &argv);
  // Init and parse options.
  GError *error = NULL;
  GOptionContext *context;
  context = g_option_context_new("- standalone dialog for file navigation.");
  g_option_context_add_main_entries(context, entries, NULL);
  g_option_context_add_group(context, gtk_get_option_group(TRUE));
  if (!g_option_context_parse(context, &argc, &argv, &error)) {
    cerr << "Arguments error: " << error->message << endl;
    return -1;
  }
  if (!project || !strlen(project)) {
    cerr << "Require project path. See -h for usage." << endl;
    return -1;
  }
  // Enable logging.
  if (verbose) {
    RegisterStdErrLogHandler();
  }
  // Create file navigator.
  Navigator navigator;
  navigator.AddProjectPath(project);
  // Create and show dialog.
  NavigateDlg dlg(&navigator);
  dlg.Update();
  dlg.Show();
  // Cleanup
  g_free(project);
  return 0;
}
